<script setup lang="ts">
import { useRouter } from 'vue-router'

interface Props {
  title?: string
  rightText?: string
  onBack?: () => void
}
type Emits = {
  (name: 'click-right'): void
}

const props = defineProps<Props>()
const emit = defineEmits<Emits>()
const router = useRouter()

const clickLeft = () => {
  if (props.onBack) {
    props.onBack()
    return
  }

  router.back()
}
</script>

<template>
  <van-nav-bar
    left-arrow
    fixed
    placeholder
    :title="title"
    :right-text="rightText"
    @click-left="clickLeft"
    @click-right="emit('click-right')"
  />
</template>

<style lang="scss" scoped>
::v-deep() {
  .van-nav-bar {
    &__arrow {
      font-size: 18px;
      color: var(--cp-text1);
    }
    &__text {
      font-size: 15px;
    }
  }
}
</style>

<!-- vue -->
useRouter useRoute()
